﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CreateImage : MonoBehaviour {
	float startPositionX;
	float startPositionY;
	Vector3 startPosition;
	int row =3;
	int colum;
	int index=1 ;
	int viTriTrongArray;
	public static  int typeCard=6;
	ArrayList array=new ArrayList();

	// Use this for initialization
	void Start () {
		if (row == 1)
						startPositionY = 0;
		if (row == 2)
						startPositionY = -1.2f;
		if (row == 3)
						startPositionY = -2.4f;
		if (row == 4)
						startPositionY = -3.8f;
		for(int i=0;i<2;i++)
		{
			for(int j =1;j<=typeCard;j++)
			{
				array.Add (j);
			}
		}
		startPosition=new Vector3(-1.5f,startPositionY,0);
		colum = typeCard*2/row;

		for (int i=0; i<colum; i++)
			for (int j=0; j<row; j++) 
			{
			index = Random.Range (0,array.Count);
			viTriTrongArray=System.Convert.ToInt32(array[index]);
			GameObject gridPlan= (GameObject)Instantiate(Resources.Load("Card"+viTriTrongArray));
			gridPlan.transform.position= new Vector3(
				startPosition.x +i*2.5f,
				startPosition.y +j*2.5f,
				startPosition.z);
			array.RemoveAt(index);
			}
	}

	// Update is called once per frame
	void Update () {
	
	}
}
